package acwing;

import java.io.*;

public class A2P2 {
    static int N=1010;
    static int[] V=new int[N];//体积
    static int[] W=new int[N];//价值
    static int[] dp=new int[N];
    static int n;//物品数量
    static int m;//背包容积
    static BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter log=new BufferedWriter(new OutputStreamWriter(System.out));
    public static void main(String[] args) throws IOException {
        String[] s = read.readLine().split(" ");
        n=Integer.parseInt(s[0]);
        m=Integer.parseInt(s[1]);
        for(int i=1;i<=n;i++){
            String[] s1 = read.readLine().split(" ");
            V[i]=Integer.parseInt(s1[0]);
            W[i]=Integer.parseInt(s1[1]);
        }
        for(int i=1;i<=n;i++){
            for(int j=m;j>=V[i];j--) dp[j]=Math.max(dp[j],dp[j-V[i]]+W[i]);
        }
        log.write(Integer.toString(dp[m]));
        log.flush();
    }
}
